home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / MySQLdb / times.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  6.1 KB  |  138 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''times module
  5.  
  6. This module provides some Date and Time classes for dealing with MySQL data.
  7. '''
  8. from time import strftime, localtime
  9. from _mysql import string_literal
  10.  
  11. try:
  12.     
  13.     try:
  14.         from mx.DateTime import Date, Time, Timestamp, ISO, DateTimeType, DateTimeDeltaType
  15.     except ImportError:
  16.         from DateTime import Date, Time, Timestamp, ISO, DateTimeType, DateTimeDeltaType
  17.  
  18.     
  19.     def DateFromTicks(ticks):
  20.         '''Convert UNIX ticks into a mx.DateTime.Date.'''
  21.         return apply(Date, localtime(ticks)[:3])
  22.  
  23.     
  24.     def TimeFromTicks(ticks):
  25.         '''Convert UNIX ticks into a mx.DateTime.Time.'''
  26.         return apply(Time, localtime(ticks)[3:6])
  27.  
  28.     
  29.     def TimestampFromTicks(ticks):
  30.         '''Convert UNIX ticks into a mx.DateTime.Timestamp.'''
  31.         return apply(Timestamp, localtime(ticks)[:6])
  32.  
  33.     
  34.     def format_DATE(d):
  35.         '''Format a DateTime object as an ISO date.'''
  36.         return d.strftime('%Y-%m-%d')
  37.  
  38.     
  39.     def format_TIME(d):
  40.         '''Format a DateTime object as a time value.'''
  41.         return d.strftime('%H:%M:%S')
  42.  
  43.     
  44.     def format_TIMESTAMP(d):
  45.         '''Format a DateTime object as an ISO timestamp.'''
  46.         return d.strftime('%Y-%m-%d %H:%M:%S')
  47.  
  48.     
  49.     def DateTime_or_None(s):
  50.         
  51.         try:
  52.             return ISO.ParseDateTime(s)
  53.         except:
  54.             return None
  55.  
  56.  
  57.     
  58.     def TimeDelta_or_None(s):
  59.         
  60.         try:
  61.             return ISO.ParseTimeDelta(s)
  62.         except:
  63.             return None
  64.  
  65.  
  66.     
  67.     def Date_or_None(s):
  68.         
  69.         try:
  70.             return ISO.ParseDate(s)
  71.         except:
  72.             return None
  73.  
  74.  
  75. except ImportError:
  76.     DateTimeDeltaType = 'DateTimeDeltaType'
  77.     DateTimeType = 'DateTimeType'
  78.     
  79.     def Date(year, month, day):
  80.         '''Construct an ISO date string.'''
  81.         return '%04d-%02d-%02d' % (year, month, day)
  82.  
  83.     
  84.     def Time(hour, min, sec):
  85.         '''Construct a TIME string.'''
  86.         return '%02d:%02d:%02d' % (hour, min, sec)
  87.  
  88.     
  89.     def Timestamp(year, month, day, hour, min, sec):
  90.         '''Construct an ISO timestamp.'''
  91.         return '%04d-%02d-%02d %02d:%02d:%02d' % (year, month, day, hour, min, sec)
  92.  
  93.     
  94.     def DateFromTicks(ticks):
  95.         '''Convert UNIX ticks to ISO date format.'''
  96.         return strftime('%Y-%m-%d', localtime(ticks))
  97.  
  98.     
  99.     def TimeFromTicks(ticks):
  100.         '''Convert UNIX ticks to time format.'''
  101.         return strftime('%H:%M:%S', localtime(ticks))
  102.  
  103.     
  104.     def TimestampFromTicks(ticks):
  105.         '''Convert UNIX ticks to ISO timestamp format.'''
  106.         return strftime('%Y-%m-%d %H:%M:%S', localtime(ticks))
  107.  
  108.     
  109.     def format_DATE(d):
  110.         """Format a date as a date (does nothing, you don't have mx.DateTime)."""
  111.         return d
  112.  
  113.     format_TIME = format_TIMESTAMP = format_DATE
  114.     TimeDelta_or_None = Date_or_None = DateTime_or_None = format_DATE
  115.  
  116.  
  117. def DateTime2literal(d, c):
  118.     '''Format a DateTime object as an ISO timestamp.'''
  119.     return string_literal(format_TIMESTAMP(d), c)
  120.  
  121.  
  122. def DateTimeDelta2literal(d, c):
  123.     '''Format a DateTimeDelta object as a time.'''
  124.     return string_literal(format_TIME(d), c)
  125.  
  126.  
  127. def mysql_timestamp_converter(s):
  128.     '''Convert a MySQL TIMESTAMP to a Timestamp object.'''
  129.     s = s + '0' * (14 - len(s))
  130.     parts = map(int, filter(None, (s[:4], s[4:6], s[6:8], s[8:10], s[10:12], s[12:14])))
  131.     
  132.     try:
  133.         return apply(Timestamp, tuple(parts))
  134.     except:
  135.         return None
  136.  
  137.  
  138.